/**
 * Created by Administrator on 2017/7/3.
 */
var vm_recruitment = avalon.define({
    $id: "recruit",
    workPlace: [],
    findJobType: [],
    isContent: false,
    jobDetail: [],
    pageJob: [],
    totalCount: 0,
    isPage: false,
    place:'',
    showContent: function (id) {
        this.isContent = true;
        getJobDetail(id);
    },
    goPage: function () {
        window.location.href = "application.html?id="+this.jobDetail.id
    },
    refresh:function (page) {
        getPageJobs(page+1);
    },
    selectPlace:function (index) {
        this.place = this.workPlace[index];
    },
    selectJob:function (index) {
        this.job = this.findJobType[index];
    }
})
init()
function init() {
    getWorkPlace();
    findJobType();
    getPageJobs();
}
function getWorkPlace() {
    var _basePath = workPlace_url();
    console.log(_basePath);
    $.ajax({
        url: _basePath,
        dataType: 'json',
        success: function (data, status, xhr) {
            console.log(JSON.stringify(data, null, 4))
            vm_recruitment.workPlace = data.resultData;
        }
    })
}

function findJobType() {
    var _basePath = findJobType_url();
    console.log(_basePath);
    $.ajax({
        url: _basePath,
        dataType: 'json',
        success: function (data, status, xhr) {
            console.log(JSON.stringify(data, null, 4))
            vm_recruitment.findJobType = data.resultData;
        }
    })
}
avalon.filters.JobType = function (str) {
    var name = '';
    var tempData = vm_recruitment.findJobType;
    for (var i = 0, len = tempData.length; i < len; i++) {
        if (str == tempData[i].value) {
            name = tempData[i].label;
        }
    }
    return name;
}

avalon.filters.workplace = function (str) {
    var name = '';
    var tempData = vm_recruitment.workPlace;
    for (var i = 0, len = tempData.length; i < len; i++) {
        if (str == tempData[i].value) {
            name = tempData[i].label;
        }
    }
    return name;
}
function getPageJobs(page) {
    var _basePath = getPageJobs_url();
    console.log(_basePath+";;page=="+page);
    $.ajax({
        url: _basePath,
        dataType: 'json',
        data: {
            pageIndex: page,
            pageSize: 10,
            workplace: vm_recruitment.place,
            jobType: vm_recruitment.job
        },
        success: function (data, status, xhr) {
            console.log(JSON.stringify(data, null, 4))
            if (data.resultStatus == 100) {
                vm_recruitment.pageJob = data.resultData;
                var pageArr = [];
                var count=data.resultData.pageObj.totalCount;
                if(count>1){
                    vm_recruitment.isPage=true;
                }
                console.log(count)
                for (var i = 1; i <= count; i++) {
                    pageArr.push(i);
                }
                vm_recruitment.totalCount = pageArr;
            } else {
                console.log(data.resultMsg);
            }

        }
    })
}
function getJobDetail(id) {
    var _basePath = job_detail_url(id);
    console.log(_basePath);
    $.ajax({
        url: _basePath,
        dataType: 'json',
        success: function (data, status, xhr) {
            console.log(JSON.stringify(data, null, 4))
            if (data.resultStatus == 100) {
                vm_recruitment.jobDetail = data.resultData;
                // $('.jobDuties').html(data.resultData.jobDuties);
            }else {
                console.log(data.resultMsg);
            }
        }
    })
}